package com.gitee.wsl.struct.tree.ext

import com.gitee.wsl.struct.tree.TreeElement
import com.gitee.wsl.struct.tree.iterator.InOrderTreeIterator
import com.gitee.wsl.struct.tree.iterator.LevelOrderTreeIterator
import com.gitee.wsl.struct.tree.iterator.PostOrderTreeIterator
import com.gitee.wsl.struct.tree.iterator.PreOrderTreeIterator
import com.gitee.wsl.struct.tree.iterator.TreeNodeIteratorType


fun <T,E: TreeElement<T, E>> TreeElement<T, E>.iterator(orderType: TreeNodeIteratorType = TreeNodeIteratorType.LevelOrder) =
    when (orderType) {
        TreeNodeIteratorType.PreOrder -> PreOrderTreeIterator(this)
        TreeNodeIteratorType.PostOrder -> PostOrderTreeIterator(this)
        TreeNodeIteratorType.LevelOrder -> LevelOrderTreeIterator(this)
        TreeNodeIteratorType.InOrder -> InOrderTreeIterator(this)
    }